<template>
  <div class="page-wrap">
    <Table filter v-bind="tableOpts" v-on="tableEvent">
      <template #operator>
        <div class="operator-wrap">
          <modifyAftersale
            v-if="authority.includes(296)"
            ref="dialogRef"
            @change="fetchCurrentTable"
          />
          <AfterSaleDetail ref="detailRef" @change="fetchCurrentTable" />
          <updateAfter ref="updateAfterRef" @change="fetchCurrentTable" />
        </div>
      </template>
    </Table>
  </div>
</template>

<script>
import tableMixins from "@/mixins/tableMixins.vue";
import modifyAftersale from "./components/modifyAftersale.vue";
import updateAfter from "./components/updateAfter.vue";
import dayjs from "dayjs";
import AfterSaleDetail from "./AfterSaleDetail.vue";
export default {
  name: "OrderAftersale",
  mixins: [tableMixins],
  components: {
    AfterSaleDetail,
    modifyAftersale,
    updateAfter,
  },
  data() {
    return {
      apiName: "newAfterSaleList",
      form: {
        storeName: {
          tag: "el-input",
          label: "订单名称",
          value: "",
          props: {
            clearable: true,
            placeholder: "请输入订单名称",
          },
        },
        status: {
          tag: "el-select",
          label: "状态",
          value: -1,
          items: [
            { label: "全部", value: -1 },
            { label: "未完成", value: 0 },
            { label: "已完成", value: 1 },
          ],
          props: {},
        },
      },
    };
  },
  computed: {
    authority() {
      const { authority = [] } =
        this.$quinn.getStorage("userDatav3") ||
        this.$store.state.userData ||
        {};
      return authority || [];
    },
  },
  methods: {
    formatQuery(params) {
      if (params.status == -1) delete params.status;
      return params;
    },
    formatData(res) {
      this.total = res?.total || 0;
      this.dataSource = (res?.data || []).map((e) => {
        if (e.updatedAt)
          e.updatedTime = dayjs(e.updatedAt).format("YYYY-MM-DD HH:mm:ss");
        if (e.createdAt) {
          e.createdTime = dayjs(e.createdAt).format("YYYY-MM-DD HH:mm:ss");
        }
        return e;
      });
    },
    handleAction(opts, row) {
      const { id, orderId, storeName: name } = row;
      let ref = null;
      if (opts == "detail") ref = this.$refs.detailRef;
      else if (opts == "delete")
        this.showConfirm(`确认删除【${name}】？`, "newAfterSaleDelete", { id });
      else if (opts == "done") ref = this.$refs.updateAfterRef;
      ref && ref.showDialog(opts, row);
    },
  },
};
</script>

<style lang="less" scoped></style>
